{include file="common/head"/} 
<div class="admin-main">
    <fieldset class="layui-elem-field layui-field-title"><legend>订单分类结算</legend></fieldset>
     <div class="demoTable layui-form"> 
            <div class="layui-inline">
                <select id="shopid" name="shopid" ng-model="field.shopid" lay-filter="shopid" lay-verify="required">
                    <option value="">请选择所属商户</option>
                    {volist name="shoplist" id="vo"}<option value="{$vo.id}">{$vo.name}</option>  {/volist}
                </select> 
            </div> 
            <div class="layui-inline"> 
                <input type="text" id="timess" name="timess" class="layui-input"placeholder="选择日期"> 
            </div>
            <div class="layui-inline">
                <input id="orderid" class="layui-input" name="orderid"  placeholder="平台订单号">
            </div>
            <div class="layui-inline">
                <input id="orderid_out" class="layui-input" name="orderid_out"  placeholder="商户订单号">
            </div>
            <button class="layui-btn layui-btn-primary" id="settles">结算</button>  
        </div>
    <div class="layui-clear"></div> 
    <table class="layui-table layui-hide" id="orderlist" lay-filter="listss"></table>
</div>    
<script src="/static/plugins/layui/layui.js"></script> 
<script type="text/html" id="action">
    {{# if(d.state==0){ }}
        <div class="layui-btn layui-btn-normal layui-btn-xs" lay-event="passit">处理</div>
    {{# }else{ }}
        <div class="layui-btn layui-btn-disabled layui-btn-xs">已处理</div>
    {{# } }} 
</script>
<script>
    layui.use(['layer','table','form','laydate'], function() {
        var table = layui.table,form = layui.form, layer = layui.layer,laydate = layui.laydate;;
        $ = layui.jquery;
        laydate.render({
            elem: '#timess',range: true,type: 'datetime'
        });
        tableIn = table.render({
            id: 'listss',
            elem: '#orderlist', 
            url: '{:url("settle")}',
            method: 'post', 
            page: true,
            cols: [[ 
                {field: 'orderid', title: '结算单号',align: 'center', width:138, fixed: true},
                {field: 'typename', title: '结算类型',align: 'center', width: 100, fixed: true},
                {field: 'money_a', title: '订单金额',align: 'center', width: 120, fixed: true}, 
                {field: 'money_s', title: '手续费',align: 'center', width: 120, fixed: true},
                {field: 'money_sf', title: '收付金额',align: 'center', width: 120, fixed: true}, 
                {field: 'state_name', title: '收付状态',align: 'center', width: 90},   
                {field: 'number', title: '订单数量',align: 'center', width: 100},
                {field: 'shopname', title: '码商/商户',align: 'center', width: 138},
                {field: 'username', title: '结算对象',align: 'center', width: 138},
                {field: 'mobile', title: '联系方式',align: 'center', width: 168},
                {field: 'addtime', title: '结算时间',align: 'center', width: 142},  
                {title: '操作', width: 80,align: 'center', fixed:'right',toolbar: '#action'},
            ]],
            limit: 60 //每页默认显示的数量
        }); 
        //结算
         $('#settles').on('click', function() {
            var shopid = $('#shopid').val();
            var timess = $('#timess').val();
            var orderid = $('#orderid').val();
            var orderid_out = $('#orderid_out').val();
            if($.trim(shopid)==='' && $.trim(timess)==='' && $.trim(orderid)==='' && $.trim(orderid_out)==='') {
                layer.msg('请选择结算条件！',{icon:0});
                return;
            }else{
                 $.ajax({
                    url:'{:url("handle_settle")}',
                    data:{'shopid':shopid,'timess':timess,'orderid':orderid,'orderid_out':orderid_out},
                    type:"Post",
                    dataType:"json",
                    success:function(data){
                        if(data.code == '1'){
                            layer.msg(data.msg);
                            location.reload();
                        }else{
                           layer.msg(data.msg); 
                        }
                        
                        
                    },
                    error:function(data){
                        $.messager.alert('错误',data.msg);
                    }
                });
            } 
        });

        table.on('tool(listss)', function(obj) {
            var data = obj.data;
            if(obj.event === 'passit') {
                var type=data.type; 
                tipss='您将进行款项操作，请慎重？';
                layer.confirm(tipss, function(index){ 
                    $.post("{:url('pass_jiesuan')}",{id:data.id},function(res){
                        if(res.code===1){
                            layer.msg(res.msg,{time:1000,icon:1},function(){ 
                                tableIn.reload();
                            });
                        }else{
                            layer.msg(res.msg,{time:1000,icon:2});
                        }
                    });
                    layer.close(index);
                });
            }
        });  
    });
</script>
</body>
</html>